<template>
	<Layout class="p-5 bg-white">
		<Form :label-width="150">
			<h1 style="text-align: center;margin: 20px;">出租车信息修改</h1>
	 <div class="content">
		<div class="width1190">		
			<form action="#" style="margin-left: 200px;" method="get" class="pro-search">
				<table>
					<tbody>
						<tr>
							<th>车龄：</th>
							<td>
								<Input v-model="car.carCondition" style="width:150px" placeholder="请输入车龄"></Input>
							</td>
						</tr>
						<tr>
							<th>里程数：</th>
							<td>
								<Input v-model="car.mileage" style="width:150px" placeholder="请输入里程数"></Input>
							</td>
						</tr>
						<tr>
							<th>品牌：</th>
							<td>
									<Select  v-model="car.brandId" style="width:150px"  transfer>
									        <Option v-for="item in brand" :value="item.brandId">{{ item.brandName }}</Option>
									</Select>
							</td>
						</tr>
						<tr>
							<th>型号：</th>
							<td>
									<Input v-model="car.type" style="width:150px" placeholder="请输入型号"></Input>	
							</td>
						</tr>
						
						<tr>
							<th>车牌归属地：</th>
							<td>
								<Input v-model="car.ownerShip" style="width:150px" placeholder="请输入车牌归属地"></Input>
							</td>
						</tr>
						<tr>
							<th>价格：</th>
							<td>
								<Input v-model="car.rentalPrice" style="width:160px" placeholder="请输入价格">
								    <span slot="append">元</span>
								</Input>
							</td>
						</tr>
						<tr>
							<th>电话号：</th>
							<td>
								<Input v-model="car.tel" style="width:160px" placeholder="请输入电话号"/>
								   
								
							</td>
						</tr>
						<tr>
							<th>微信号：</th>
							<td>
								<Input v-model="car.wxNumber" style="width:160px" placeholder="请输入微信号"/>(非必填)
							</td>
						</tr>
						<tr>
							<th>标题图片:</th>
							<td>
								<div v-if="car.imgUrl != ''">
								  <img
								    :src="car.imgUrl"
								    style="width:180px;height:120px"
								  />
								  <div class="demo-upload-list-cover">
								    <Icon
								      type="ios-trash-outline"
								      @click.native="handleRemove"
								    ></Icon>
								  </div>
								</div>
								<Upload
								  with-credentials
								  :max-size="2048"
								  :show-upload-list="false"
								  name="file"
								  ref="upload"
								  :format="['jpg', 'jpeg', 'png']"
								  :data="{ module: 'car', date: new Date() }"
								  :on-format-error="handleFormatError"
								  :on-exceeded-size="handleMaxSize"
								  :on-success="handleSuccess"
								  :action="url"
								>
								  <Button icon="ios-cloud-upload-outline" style="margin-top: 5px"
								    >上传</Button
								  >
								</Upload>
							</td>
						</tr>
						<tr>
							<th>多图片上传:</th>
							<td>
								<div v-if="imgUrlList != ''" v-for="(item,index) in imgUrlList" :key="index">
								  <img
								    :src="imgUrlList[index].imgUrl"
								    style="width:180px;height:120px;display: inline-block;"
								  />
								  <div class="demo-upload-list-cover">
								    <Icon
								      type="ios-trash-outline"
								      @click.native="handleListRemove()"
								    ></Icon>
									
								  </div>
								</div>
								<Upload
								  with-credentials
								  :max-size="2048"
								  :show-upload-list="false"
								  name="file"
								  ref="upload"
								  multiple
								  type="drag"
								  :format="['jpg', 'jpeg', 'png']"
								  :data="{ module: 'car', date: new Date() }"
								  :on-format-error="handleFormatError"
								  :on-exceeded-size="handleMaxSize"
								  :on-success="handleListSuccess"
								  :action="url"
								   style="display: inline-block;width:58px;"
								>
								  <div style="width: 58px;height:58px;line-height: 58px;">
								              <Icon type="ios-camera" size="20"></Icon>
								          </div>
								</Upload>
							</td>
						</tr>
						<tr>
							<th></th>
							<td>
								<Button @click="submit" type="primary" style="margin-right: 100px;">提交</Button>
								
								<Button @click="cancel" class="ml-2">取消</Button>
							</td>
						</tr>
						
						
						
						
					</tbody>
				</table>		
			</form>	
		</div>			
	</div>				
		 
		</Form>
	</Layout>
</template>
<script>

	export default {
		data() {
			return {
				iport:'',
				url:'',
				carSellInfoId:'',
				proviences : [],
				citys : [],
				currentUser:{},
				imgUrlList:[],
				imgList:[],
				img:'',
				imgs:'',
				regins : [],
				car:{
					carCondition: null,//车龄
					mileage: null,//表显里程
					brandId: null,//
					type: "",//车型
					ownerShip:'',//车牌归属地
					imgUrl:'',//图片
					rentalPrice:'',//卖车价格
					personName:'',//卖家姓名
					tel:'',//电话号码
					wxNumber:'',
					carRentalInfoId:'',
					carId:'',
					clientId: '',
				},
				styleList: [{
						value: '三厢车',
						label: '三厢车'
					},
					{
						value: '两厢车',
						label: '两厢车'
					},
					{
						value: 'SUV',
						label: 'SUV'
					},
					{
						value: '掀背车',
						label: '掀背车'
					},
					{
						value: '跑车',
						label: '跑车'
					},
					{
						value: 'MPV',
						label: 'MPV'
					},
					{
						value: '敞篷车',
						label: '敞篷车'
					},
					{
						value: '旅行车',
						label: '旅行车'
					},
					{
						value: '皮卡',
						label: '皮卡'
					},
					{
						value: '客车',
						label: '客车'
					},
					{
						value: '货车',
						label: '货车'
					}
				],
				brand:[],
				paifangList: [{
						value: '国四',
						label: '国四'
					},
					{
						value: '国五',
						label: '国五'
					},
					{
						value: '国六',
						label: '国六'
					},
					{
						value: '国六B',
						label: '国六B'
					}
				
				],
				styleList: [{
						value: '三厢车',
						label: '三厢车'
					},
					{
						value: '两厢车',
						label: '两厢车'
					},
					{
						value: 'SUV',
						label: 'SUV'
					},
					{
						value: '掀背车',
						label: '掀背车'
					},
					{
						value: '跑车',
						label: '跑车'
					},
					{
						value: 'MPV',
						label: 'MPV'
					},
					{
						value: '敞篷车',
						label: '敞篷车'
					},
					{
						value: '旅行车',
						label: '旅行车'
					},
					{
						value: '皮卡',
						label: '皮卡'
					},
					{
						value: '客车',
						label: '客车'
					},
					{
						value: '货车',
						label: '货车'
					}
				],
				pinpai: [],
				paifangList: [{
						value: '国四',
						label: '国四'
					},
					{
						value: '国五',
						label: '国五'
					},
					{
						value: '国六',
						label: '国六'
					},
					{
						value: '国六B',
						label: '国六B'
					}
				
				],
				ranyouList: [{
						value: '汽油',
						label: '汽油'
					},
					{
						value: '柴油',
						label: '柴油'
					},
					{
						value: '电动',
						label: '电动'
					},
					{
						value: '油电混合',
						label: '油电混合'
					},
					{
						value: '其它',
						label: '其它'
					}
				],
				qudongList: [{
						value: '前驱',
						label: '前驱'
					},
					{
						value: '后驱',
						label: '后驱'
					},
					{
						value: '四驱',
						label: '四驱'
					}
				],
				biansuList: [{
						value: '手动',
						label: '手动'
					},
					{
						value: '自动',
						label: '自动'
					}
				]
				
			}
		},
		methods: {
			//图片上传时文件格式错误方法
			handleFormatError(file) {
			  this.$Notice.warning({
			    title: '文件格式不正确',
			    desc:
			      '文件 ' +
			      file.name +
			      ' 格式不正确，请上传 jpg 或 png 或 jpeg格式的图片。',
			  })
			},
			//校验图片的大小，不能大于2M
			handleMaxSize: function(file) {
			  this.$Modal.info({
			    title: '超出文件大小限制',
			    content: '文件 ' + file.name + ' 太大，不能超过 2M。',
			  })
			},
			handleRemove(file) {
			  // 从 upload 实例删除数据 
			  this.$data.car.imgUrl = ''
			},
			//上传成功后的勾子 
			handleSuccess: function(response, file, fileList) {
				
			  this.$data.car.imgUrl = response.DATA.URL
			  console.log( this.$data.car.imgUrl)
			},
			
			handleListRemove(file) {
			  // 从 upload 实例删除数据 
			  this.$data.imgUrlList = []
			},
			//上传成功后的勾子 
			handleListSuccess: function(response, file, fileList) {
				this.$data.imgs = response.DATA.URL
			  var img = {}
			  img.carId = this.$data.car.carId
			  img.imgUrl = this.$data.imgs
			  console.log(img)
			  this.$data.imgUrlList.unshift(img)
			  
			  // this.$data.imgUrlList.carId = this.$data.car.carId
			  // this.$data.imgUrlList.imgUrl = response.DATA.URL
			  console.log( this.$data.imgUrlList)
			},
			
			ss:function(item){
				console.log(this.house)
			},
			getCarList:function(){
				this.http.get({
					url:'/car-rental-info/info',
					param:{ carId:this.$data.car.carId }
				}).then((data) => {
					this.$data.car = data
					console.log(data)
				})
			},
			getBrand() {
				this.http.get({
					url: "/brand/list",
					param: {}
				}).then(data => {
					this.$data.brand = data
				});
			},
			
			submit: function() {
        if(this.$data.car.tel === ""){
          this.message.error("电话必须输入");
          return;
        }
				console.log(this.$data.carId)
				this.cancelImg()
				let self = this;
				this.http.put({
					url: "/car-rental-info/info",
					param: {
						
						carCondition: this.$data.car.carCondition,
						mileage: this.$data.car.mileage,
						brandId: this.$data.car.brandId,
						type: this.$data.car.type,
						ownerShip:this.$data.car.ownerShip,
						imgUrl:this.$data.car.imgUrl,
						country:this.$data.car.country,
						rentalPrice:this.$data.car.rentalPrice,
						personName:this.$data.car.personName,
						tel:this.$data.car.tel,
						wxNumber:this.$data.car.wxNumber,
						carId:this.$data.car.carId,
						clientId:1001,
					    
					}
				}).then(data => {
					this.$Notice.success({title:"修改成功"});	
					this.updataImg()
					this.cancel()
				});
			},
			cancel: function() {
				this.$router.push({
					name: "user_center_car_zu",
					params: {}
				});
			},
			cancelImg:function(){
				this.http.delete({
					url:`/car/image/remove/${this.$data.car.carId}`,
				}).then(data => {
					
					console.log("55")
				})
			},
			updataImg: function(){
				var imgs = []
				for(var i = 0;i<this.$data.imgUrlList.length;i++){
					imgs.unshift(this.$data.imgUrlList[i].imgUrl)
				}
				var imgString = imgs.toString()
				this.http.put({
					url:'/car/image/upload',
					param:{
						carId:this.$data.car.carId,
						images:imgString
					}
				}).then(data => {
					console.log("shangchuanl")
				})
			},
			searchImg:function(){
				this.http.get({
					url:`/car/image/list/${this.$data.car.carId}`,
				}).then(data => {
					this.$data.imgUrlList = data
					console.log(data)
				})
			},
		},
		created: function() {
			this.$data.currentUser = JSON.parse(sessionStorage.getItem('CURRENT'))
			this.$data.car.clientId = this.$data.currentUser.client.clientId
			this.$data.car.carId = this.$route.params.carId;
			console.log(this.$data.car.carId)
			this.iport = this.store.state.iport
			this.url = this.iport + 'image/upload'
			this.getCarList()
			this.searchImg()
			this.getBrand();
			// var cli = this.local.session.getItem("CURRENT");
			// this.houseSell.clientId = cli.client.clientId;
		},
		beforeRouteLeave(to, from, next) {
		    this.$destroy();//手动销毁当前页面
		    next();
		},
	}
</script>

<style >
</style>
